import java.io.File;

public class Leetcode1615 {


    public static void main(String[] args) {
        File directory = new File("/Users/hjl/Downloads/StudInfo0");
        File[] files = directory.listFiles();
        for (File file : files) {
            if (file.isFile()) {
                String fileName = file.getName();
                String newFileName = fileName.replaceAll(" ", "");
                int lastDotIndex = newFileName.lastIndexOf(".");
                String extension = newFileName.substring(lastDotIndex);
                String newName = newFileName.substring(0, lastDotIndex).concat(".").concat(extension);
                File newFile = new File(directory, newName);
                file.renameTo(newFile);
            }
        }
    }

    public static int maximalNetworkRank(int n, int[][] roads) {
        int[] count = new int[n];
        boolean[][] flag = new boolean[n][n];

        for (int[] road : roads) {
            count[road[0]]++;
            count[road[1]]++;
            flag[road[0]][road[1]] = true;
            flag[road[1]][road[0]] = true;
        }

        int max = 0;
        int maxIndex = 0;
        int lastMax = 0;
        int lastMaxIndex = 0;
        for (int i = 0; i < count.length; i++) {
            if (count[i] > max) {
                lastMax = max;
                lastMaxIndex = maxIndex;
                max = count[i];
                maxIndex = i;
            } else if (count[i] == max && !flag[maxIndex][i]) {
                lastMax = max;
                lastMaxIndex = maxIndex;
                max = count[i];
                maxIndex = i;
            } else {
                if (count[i] > lastMax) {
                    lastMax = count[i];
                    lastMaxIndex = i;
                } else if (count[i] == lastMax && !flag[maxIndex][i]) {
                    lastMax = count[i];
                    lastMaxIndex = i;
                }
            }
        }

        return max + lastMax - (flag[maxIndex][lastMaxIndex] ? 1 : 0);
    }
}
